package org.example.volunteerend.service.impl;

import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import org.example.volunteerend.dto.PageResponse;
import org.example.volunteerend.entity.PointsRecord;
import org.example.volunteerend.entity.ServiceRecord;
import org.example.volunteerend.mapper.PointsRecordMapper;
import org.example.volunteerend.mapper.ServiceRecordMapper;
import org.example.volunteerend.service.UserRecordService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class UserRecordServiceImpl implements UserRecordService {
    private final ServiceRecordMapper serviceRecordMapper;
    private final PointsRecordMapper pointsRecordMapper;

    @Override
    public PageResponse<ServiceRecord> getServiceRecords(Integer userId, Integer pageNum, Integer pageSize) {
        // 设置分页
        PageHelper.startPage(pageNum, pageSize);
        
        // 查询数据
        List<ServiceRecord> records = serviceRecordMapper.findByUserId(userId);
        long total = serviceRecordMapper.countByUserId(userId);
        
        return new PageResponse<>(records, total, pageNum, pageSize);
    }

    @Override
    public PageResponse<PointsRecord> getPointsRecords(Integer userId, Integer pageNum, Integer pageSize) {
        // 设置分页
        PageHelper.startPage(pageNum, pageSize);
        
        // 查询数据
        List<PointsRecord> records = pointsRecordMapper.findByUserId(userId);
        long total = pointsRecordMapper.countByUserId(userId);
        
        return new PageResponse<>(records, total, pageNum, pageSize);
    }
} 